% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
\PassOptionsToPackage{dvipsnames,svgnames,x11names}{xcolor}
%
\documentclass[
  letterpaper,
  DIV=11,
  numbers=noendperiod]{scrartcl}

\usepackage{amsmath,amssymb}
\usepackage{iftex}
\ifPDFTeX
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math}
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
\usepackage{lmodern}
\ifPDFTeX\else  
    % xetex/luatex font selection
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
  \usepackage[]{microtype}
  \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
  \IfFileExists{parskip.sty}{%
    \usepackage{parskip}
  }{% else
    \setlength{\parindent}{0pt}
    \setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
  \KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
% Make \paragraph and \subparagraph free-standing
\ifx\paragraph\undefined\else
  \let\oldparagraph\paragraph
  \renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
  \let\oldsubparagraph\subparagraph
  \renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi


\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}\usepackage{longtable,booktabs,array}
\usepackage{calc} % for calculating minipage widths
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\makeatletter
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
\makeatother
% Allow footnotes in longtable head/foot
\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
\makesavenoteenv{longtable}
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
% definitions for citeproc citations
\NewDocumentCommand\citeproctext{}{}
\NewDocumentCommand\citeproc{mm}{%
  \begingroup\def\citeproctext{#2}\cite{#1}\endgroup}
\makeatletter
 % allow citations to break across lines
 \let\@cite@ofmt\@firstofone
 % avoid brackets around text for \cite:
 \def\@biblabel#1{}
 \def\@cite#1#2{{#1\if@tempswa , #2\fi}}
\makeatother
\newlength{\cslhangindent}
\setlength{\cslhangindent}{1.5em}
\newlength{\csllabelwidth}
\setlength{\csllabelwidth}{3em}
\newenvironment{CSLReferences}[2] % #1 hanging-indent, #2 entry-spacing
 {\begin{list}{}{%
  \setlength{\itemindent}{0pt}
  \setlength{\leftmargin}{0pt}
  \setlength{\parsep}{0pt}
  % turn on hanging indent if param 1 is 1
  \ifodd #1
   \setlength{\leftmargin}{\cslhangindent}
   \setlength{\itemindent}{-1\cslhangindent}
  \fi
  % set entry spacing
  \setlength{\itemsep}{#2\baselineskip}}}
 {\end{list}}
\usepackage{calc}
\newcommand{\CSLBlock}[1]{\hfill\break\parbox[t]{\linewidth}{\strut\ignorespaces#1\strut}}
\newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{\strut#1\strut}}
\newcommand{\CSLRightInline}[1]{\parbox[t]{\linewidth - \csllabelwidth}{\strut#1\strut}}
\newcommand{\CSLIndent}[1]{\hspace{\cslhangindent}#1}

\KOMAoption{captions}{tableheading}
\makeatletter
\@ifpackageloaded{caption}{}{\usepackage{caption}}
\AtBeginDocument{%
\ifdefined\contentsname
  \renewcommand*\contentsname{Table of contents}
\else
  \newcommand\contentsname{Table of contents}
\fi
\ifdefined\listfigurename
  \renewcommand*\listfigurename{List of Figures}
\else
  \newcommand\listfigurename{List of Figures}
\fi
\ifdefined\listtablename
  \renewcommand*\listtablename{List of Tables}
\else
  \newcommand\listtablename{List of Tables}
\fi
\ifdefined\figurename
  \renewcommand*\figurename{Figure}
\else
  \newcommand\figurename{Figure}
\fi
\ifdefined\tablename
  \renewcommand*\tablename{Table}
\else
  \newcommand\tablename{Table}
\fi
}
\@ifpackageloaded{float}{}{\usepackage{float}}
\floatstyle{ruled}
\@ifundefined{c@chapter}{\newfloat{codelisting}{h}{lop}}{\newfloat{codelisting}{h}{lop}[chapter]}
\floatname{codelisting}{Listing}
\newcommand*\listoflistings{\listof{codelisting}{List of Listings}}
\makeatother
\makeatletter
\makeatother
\makeatletter
\@ifpackageloaded{caption}{}{\usepackage{caption}}
\@ifpackageloaded{subcaption}{}{\usepackage{subcaption}}
\makeatother
\ifLuaTeX
  \usepackage{selnolig}  % disable illegal ligatures
\fi
\usepackage{bookmark}

\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same} % disable monospaced font for URLs
\hypersetup{
  pdftitle={jwdid: A Stata command for the estimation of Difference-in-Differences models using ETWFE},
  colorlinks=true,
  linkcolor={blue},
  filecolor={Maroon},
  citecolor={Blue},
  urlcolor={Blue},
  pdfcreator={LaTeX via pandoc}}

\title{jwdid: A Stata command for the estimation of
Difference-in-Differences models using ETWFE}
\author{}
\date{}

\begin{document}
\maketitle

\subsection{Estimation of DID models using
ETWFE}\label{estimation-of-did-models-using-etwfe}

In this section, we describe the Stata command \texttt{jwdid} that
implements the estimation of DID models using the ETWFE estimator
proposed by Jeffrey M. Wooldridge (2021). One of the main advantages of
Jeffrey M. Wooldridge (2021)'s estimator is that by being a simple
extension of the standard FE estimator, it can be easily modified and
implemented to allow for other types of non-linear models. As described
in Jeffrey M. Wooldridge (2023), the ETWFE estimator could be used, for
example, to model cases where the dependent variable is binary (logit)
or count data (poisson). A second advantage of the ETWFE estimator is
that the estimation of the baseline model, is transparent as it does not
require the use of specialized software, except for the estimation of
fixed effects models. This is in contrast with other DID estimators like
the ones proposed by Callaway and Sant'Anna (2021), De Chaisemartin and
D'Haultfœuille (2020), or Borusyak, Jaravel, and Spiess (2024), where
the bulk of the model estimation is done in the background, with the
user having less control and understanding on what is being estimated.

Thanks to this transparency in model specification,
(\textbf{yotov2023?}) propose a large set of recommendations for the
analysis of DID models in the context of international trade and Gravity
models. On this regard, we present the command \texttt{jwdid} as a
flexible command in Stata that allows to consider (\textbf{yotov2003?})
recommendations for the estimation of DID models, in the framework of
trade models.

\subsubsection{Base line model}\label{base-line-model}

As described in Jeffrey M. Wooldridge (2021), the baseline model for the
estimation of the DID model using the ETWFE estimator is the following:

\begin{equation}\phantomsection\label{eq-b0}{Y_{i,t} = \alpha + \sum_{g \in G} \sum_{t=g}^{T} \theta_{g,t} D_{i,g,t} + \xi_i + \xi_t + \varepsilon_{i,t}
}\end{equation}

where \(Y_{i,t}\) is the dependent variable, \(D_{i,g,t}\) is a dummy
that takes the value of 1 if the observation is in the treatment group
\(g\), on period \(t\) and 0 otherwise. \(G\) is a set that indicates at
what time treatment started for all observations, and \(T\) is the last
period of the analysis.

\(\xi_i\) and \(\xi_t\) are sets of fixed effects for the individual and
time dimensions, respectively.\footnote{Often, one can use group fixed
  effects instead of individual fixed effects, and would still obtain
  numerically identical results in the linear model case.} In this
setup, the \(\theta_{g,t}\) coefficients represent the average treatment
effect that the treatment group \(g\) experiences at time \(t\)
(\(ATT(g,t)\)). As described in Jeffrey M. Wooldridge (2021), allowing
for a flexible specification of the \(\theta_{g,t}\) avoids the problem
of bad controls and negative weights that have been identified in the
literature as potential problems in the estimation of DID models using
traditional TWFE estimators.

This command can be directly estimated with \texttt{jwdid} using the
following syntax:

\texttt{jwdid\ y,\ ivar(i)\ tvar(t)\ gvar(g)}

Where \texttt{y} is the dependent variable, \texttt{ivar(i)} is used to
identify the individual panel data dimension, \texttt{tvar(t)}
identifies the time dimension, and \texttt{gvar(g)} identifies the
treatment group. Specifically, for observation \(i\), \(g\) would take
the value of zero if the panel observation is never treated (within the
window of the analysis), and would take a value different from zero to
indicate the year that treatment started for unit \(i\). Following
standard assumptions, this specification assumes that the treatment is
an absorbing status, meaning that once a unit is treated, it remains
treated for the rest of the analysis.

By default, \texttt{jwdid} will estimate the baseline model
Equation~\ref{eq-b0} using the \texttt{reghdfe} command (Correia 2016),
assuming clustered standard errors at \texttt{i} level. If other level
is desired, the user can specify the \texttt{cluster(cvar)} option.
While the command does not impose the assumption that the data is a
panel, the methodology is designed to work with panel data. In case of
repeated crossection, one should instead use the following syntax:

\texttt{jwdid\ y,\ tvar(t)\ gvar(g)\ {[}cluster(cvar){]}}

By excluding \texttt{ivar(i)}, the command assumes data is a repeated
crossection, proceeding to include group fixed effects only. The
\texttt{cluster(cvar)} option is not required, but can be used to
request Standard errors to be clusted at the level \texttt{cvar}.

Specifically, this command will estimate the following model:

\begin{equation}\phantomsection\label{eq-b1}{Y_{i,t} = \alpha + \sum_{g \in G} \sum_{t=g}^{T} \theta_{g,t} D_{i,g,t} + \xi_g + \xi_t + \varepsilon_{i,t}
}\end{equation}

This model specification makes the implicit assumption that Parallel
trends are satisfied, using all never treated and not-yet treated
observations as controls (not included category) for the identification
of treatment effects.

If one instead wants to relax this assumption, the user can specify the
option \texttt{never}:

\texttt{jwdid\ y,\ ivar(i)\ tvar(t)\ gvar(g)\ never}

Which will estimate the following model:

\begin{equation}\phantomsection\label{eq-b2}{Y_{i,t} = \alpha +  \sum_{g \in G} \sum_{t=t_0}^{g-1} \theta^{pre}_{g,t} D_{i,g,t}+ \sum_{g \in G} \sum_{t=g}^{T} \theta^{post}_{g,t} D_{i,g,t} + \xi_i + \xi_t + \varepsilon_{i,t}
}\end{equation}

This is in principle the same as strategy as the one proposed by Sun and
Abraham (2021), allowing for full heterogeneity across all groups and
all relative periods. This specification is also numerically identical
to the one proposed by Callaway and Sant'Anna (2021), for the case where
there are no covariates. In this case, the only observations that are
used as controls are the ones that were never treated. In this
specification, all \(\theta^{pre}_{g,t}\) can be used to test for the
parallel trends assumption, and all \(\theta^{post}_{g,t}\) can be used
to estimate the treatment effects.

\subsubsection{Extensions: Nonlinear
models}\label{extensions-nonlinear-models}

As described in Jeffrey M. Wooldridge (2023), the standard ETWFE model
described in Equation~\ref{eq-b0} or Equation~\ref{eq-b1} identifies the
average treatment effect imposing a linear parallel trends assumption.
However, such assumption may not be valid in cases, such as when the
dependent variable follows some limited distribution. Roth and Sant'Anna
(2023) discusses a similar problem, stating that the choice of
transformation of the dependent variable is crucial for the
identification of the average treatment effect, and only under certain
conditions would the ATT be identified for any transformation.

In this regard, Jeffrey M. Wooldridge (2023) proposes that the linear
ETWFE models can be adapted to allow for non-linear models, by simply
imposing the linear PTA assumption only on the latent variable of the
model, but not the outcome itself.

Consider the following transformation of the model defined by
Equation~\ref{eq-b2}:

\begin{equation}\phantomsection\label{eq-e1}{E(Y_{i,t}|X,\xi_i,\xi_t) = H\left(\alpha +  \sum_{g \in G} \sum_{t=t_0}^{g-1} \theta^{pre}_{g,t} D_{i,g,t}+ \sum_{g \in G} \sum_{t=g}^{T} \theta^{post}_{g,t} D_{i,g,t} + \xi_i + \xi_t \right)
}\end{equation}

This specification focuses on identifying the conditional expected value
of the outcome of interest as function of the treatment status, and the
individual and time fixed effects. If we assume the \(H()\) is the
identify function, we would be back to the linear model described by
Equation~\ref{eq-b2}. However, if we assume that \(H()\) is a non-linear
function, like exponetial for poisson, or logistic for logit models, we
could estimate the average treatment effect under different assumptions,
imposing only linear PTA on the latent variable of the model.

The \texttt{jwdid} command allows the user to specify the
\texttt{method()} option to estimate models described by
Equation~\ref{eq-e1}, where one would specificy the regression model to
be estimated, followed by the options associated with that model. For
example, if we would be interested in estimating a poisson model, we
would use the following syntax:

\texttt{jwdid\ y,\ ivar(i)\ tvar(t)\ gvar(g)\ never\ method(poisson)}

There is no restrictions on the type \texttt{method} one can use with
the \texttt{jwdid} command, but it has not been tested with all possible
models. The user should be aware that the \texttt{method()} option is
passed directly for the model estimation step, and the user should be
familiar with the syntax of the model being estimated.

It should be noted that when estimating non-linear models with a large
number of fixed effects, one may face an incidental parameters problem.
This is not generally a problem for the linear case, because the
parameters of interest can be identified without explicitly estimating
the fixed effects, using, for example the within transformation.
However, with the exception of poisson models, fixed effects are
generally estimated raising the possibility of incidental parameters. To
reduce the impact of this problem, whenver \texttt{method()} is
specified \texttt{jwdid} will incorporate \emph{group} fixed effects,
instead of \emph{individual} fixed effects.

For the linear case with balanced data, using \emph{group} instead of
\emph{individual} fixed effects provides numerically identical results.
If panel is unbalanced the results will not be identical. In such cases,
the option \texttt{corr} will create additional variables that address
the difference. In the case of non-linear models, the best solution is
to use \emph{group} fixed effects. However, if one is interested in
poisson models, the alterantive to group fixed effects is to use
\texttt{ppmlhdfe} (Correia, Guimarães, and Zylkin (2020)).\footnote{ The
  correction implemented with \texttt{corr} is not useful to recover the
  coefficients from \texttt{ppmlhdfe} using \texttt{poisson} command}
This is the state-of-the-art estimator for poisson models with fixed
effects, and it is the recommended estimator for trade analysis.

\subsubsection{Extensions: Covariates}\label{sec-cov}

As described in Jeffrey M. Wooldridge (2021), it is possible to include
covariates in the model, by simply adding corrections that enable to
easily identify the average treatment effect. However, following the
literature on DID models, the implicit assumption is that covariates are
time-invariant. \texttt{jwdid} does not impose any assumption on the
covariates, but the user should be aware of the implications.

In general, when covariates are considered, the model of interest is
similar to Equation~\ref{eq-b2}, but adjusted for covariates:

\begin{equation}\phantomsection\label{eq-e2}{
\begin{aligned}
Y_{i,t} &= \alpha +  \sum_{g \in G} \sum_{t=t_0}^{g-1} \theta^{pre}_{g,t} D_{i,g,t}+
\sum_{g \in G} \sum_{t=g}^{T} \theta^{post}_{g,t} D_{i,g,t} + \sum_{g \in G} \sum_{t=t_0}^{g-1} D_{i,g,t} \tilde x_{i}'\beta^{pre}_{g,t} + 
\sum_{g \in G} \sum_{t=g}^{T} D_{i,g,t} \tilde x_{i}'\beta^{post}_{g,t} \\
&+ x_{i}'\beta + \sum_{t=t_0}^{T} D_{i,t} x_{i}'\beta_t + \sum_{g\in G} D_{i,g} x_{i}'\beta_g
\xi_i + \xi_t + \varepsilon_{i,t}
\end{aligned}}\end{equation}

Where \(D_{i,t}\) is a dummy variable that is equal to 1 if period is
equal to \(t\), and \(D_{i,g}\) is a dummmy variable that is equal to 1
if the group membership is equal to \(g\), and zero otherwise.
\(\tilde x_{i}\) are the within cohort and period demeaned variables.
When using \texttt{reghdfe} or \texttt{ppmlhdfe} the term
\(\sum_{g\in G} D_{i,g} x_{i}'\beta_g\) is ommitted if all covariates
are time constant.

Using \(\tilde x\), default option, is not necessarity for the
estimation of treatment effects. However, if one uses that
specification, the parameters \(\theta^{pre}_{g,t}\) and
\(\theta^{post}_{g,t}\) still identify the average treatment effect for
group \(g\) at time \(t\). One could also use the untransformed
covariates in Equation~\ref{eq-e2}, and still be able to obtained the
same group/time specific treatment effects with the post estimation
commands.

From the user persective, \texttt{jwdid} would simply need to be called
as follows:

\texttt{jwdid\ y\ x,\ ivar(i)\ tvar(t)\ gvar(g)\ never\ {[}xasis{]}}

Where \texttt{x} are all covariates of interest. If one uses the option
\texttt{xasis}, the command will use the covariates without demeaning
them, which may save some computation time.

\subsubsection{Extensions: Treatment Heterogeneity}\label{sec-het}

As it may be aparent from Equation~\ref{eq-e2}, the number of estimated
parameters can grow quickly with the number groups/cohorts, periods of
analysis, and covariates. This could lead to increasing computational
burden of the estimation. An alternative, which is already implemented
via \texttt{xthdidregress} and \texttt{hdidregress} in Stata 18, is to
estimate the model that reduces the heterogeneity of the treatment
effects. Specifically, it allows treatment effects to vary across
cohorts, across absolute time, or across relative time.

For the case without covariates, the specification of
Equation~\ref{eq-b2} can be modified to impose the heterogeneity
restrictions as follows:

Time heterogeneity:

\begin{equation}\phantomsection\label{eq-ht1}{Y_{i,t} = \alpha +  \sum_{t=t_0}^T \theta^{pre}_{t} D_{i,t,pre} + \sum_{t=t_0}^T \theta^{post}_{t}  D_{i,t,post}+ \xi_i + \xi_t + \varepsilon_{i,t}
}\end{equation}

Cohort heterogeneity:

\begin{equation}\phantomsection\label{eq-ht2}{Y_{i,t} = \alpha +  \sum_{g\in G} \theta^{pre}_{g}  D_{i,g,pre}+ \sum_{g\in G} \theta^{post}_{g} D_{i,g,post} + \xi_i + \xi_t+\varepsilon_{i,t}
}\end{equation}

Event (Relative Time) heterogeneity:

\begin{equation}\phantomsection\label{eq-ht3}{Y_{i,t} = \alpha +  \sum_{e = E_{min}}^{-2} \theta_{e} D_{i,e}+ \sum_{e = 0}^{E_{max}} \theta_{e} D_{i,e} + \xi_i + \xi_t+\varepsilon_{i,t}
}\end{equation}

Where \(D_{i,t,pre}\) and \(D_{i,t,post}\) are dummies that take the
value of 1 if observation \(i\), which is part of an eventually treated
group, is not yet treated or is already treated at time \(t\),
respectively. \(D_{i,g,pre}\) and \(D_{i,g,post}\) are dummies that take
the value of 1 if observation \(i\) belongs to group \(g\) and is not
yet treated or is already treated at time \(t\), respectively.
\(D_{i,e}\) is a dummy that takes the value of 1 if observation \(i\) is
\(e\) periods relative to when treatment started. \(E_{min}\) and
\(E_{max}\) are the minimum and maximum event periods, possible. The
\emph{pre} coefficients are only considered when the \texttt{never}
option is used.

The \texttt{jwdid} command allows the user to specify each one of these
restrictions using the \texttt{hettype()} option.

\texttt{jwdid\ y,\ ivar(i)\ tvar(t)\ gvar(g)\ hettype(option)}

Where \texttt{option} can be \texttt{time}, \texttt{cohort}, or
\texttt{event}. If no option is selected, the command will estimate the
model described by Equation~\ref{eq-b2} which is the equivalent to
allowing for full Cohort-time heterogeneity.

\subsubsection{Extensions: Other
Options}\label{extensions-other-options}

As described in Section~\ref{sec-cov}, when covariates are considered in
the model, the default option is to interact all covariates (or the
demeaned transformations) with the same level of covariate
heterogeneity. Some times, however, one may not be interested in
estimating the same level of heterogeneity for all covariates. It may be
possible, for example, to consider separate sets of covariates that
could be interacted only with the time or the group dimensions.

Specifically, assume there are no variables we wish to consider for the
treatment heterogeneity, but instead consider three sets of covariates:
\(x^{EX}\) or variables we wish to incorporate without further
interactions, \(x^{T}\) or variables that would be interacted with the
Time variables only, and \(x^{G}\) or variables that would be interacted
with group indicators only. In this case the setup would be:

\begin{equation}\phantomsection\label{eq-op1}{\begin{aligned}
Y_{i,t} &= \alpha +  \sum_{g \in G} \sum_{t=t_0}^{g-1} \theta^{pre}_{g,t} D_{i,g,t}+
\sum_{g \in G} \sum_{t=g}^{T} \theta^{post}_{g,t} D_{i,g,t} \\
&+ x'^{EX}_{i}\beta + \sum_{t=t_0}^{T} D_{i,t} x'^{T}_{i}\beta_t + \sum_{g\in G} D_{i,g} x'^{G}_{i}\beta_g
\xi_i + \xi_t + \varepsilon_{i,t}
\end{aligned}
}\end{equation}

This specification can be estimated using the following syntax:

\texttt{jwdid\ y\ ,\ ivar(i)\ tvar(t)\ gvar(g)\ never\ exogvar(x\_ex)\ xtvar(x\_t)\ xgvar(x\_g)}

If covariates are included after \texttt{y}, they would still be treated
following the specification of Equation~\ref{eq-e2}, or following any of
the heterogeneity restrictions described in Section~\ref{sec-het}.

An advanced version of this option is the inclusion of high order fixed
effects (and interactions with fixed effects) that are different from
the individual and time fixed effects. It is possible to request the
inclusion of those types of fixed effects using the option
\texttt{fevar()}, which is only valid if one is using the default
estimator method \texttt{reghdfe} or \texttt{ppmlhdfe}. In both cases,
the additional fixed effects (or interactions) are included in the
estimation of the model without further interactions.

\subsection{Post estimation: Aggregated treatment
effects}\label{sec-agg}

After the estimation of the model, under the default options, one can
use the coefficients \(\theta^{post}_{g,t}\) as direct estimates of the
group and time specific average tretment effects on the treated.
However, one may also be interested in estimating aggregated ATTs for
the overall data, across groups or periods, or dynamic effects.
Furthermore, when the underlying method is a non-linear model, these
coefficients cannot be directly interpreted as the average treatment
effect on the outcome, but only on the latent variable.

\texttt{jwdid} comes along with the post estimation command
\texttt{jwdid\_estat} that can be used for that purpose. Internally, it
uses the \texttt{margins} command to identify average treatment effects
under the following algorithm:

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
  Using the model estimates, predict the outcome of interest for all
  observations given the observed covariates and fixed effects. Call
  this \(\hat Y(obs)\) or predicted outcome under the observed
  covariates. The model prediction could be the linear prediction, or
  the predicted probability in the case of logit models, or the
  predicted count in the case of poisson models.
\item
  Consider the specification Equation~\ref{eq-e2}, and assume that all
  \(\theta^{post}_{g,t}\) (and \(\theta^{pre}_{g,t}\) if \texttt{never}
  is used), as well as all \(\beta^{post}\) and \(\beta^{pre}\) are
  zero, and predict the outcome of interest. Call this \(\hat Y(0)\) or
  predicted outcome under the counterfactual scenario of no treatment.
\end{enumerate}

In this case, the predicted Average Treatment Effect on the Treated for
observation \(i\) is given by:

\[\widehat{ATT}_i = \hat Y(obs) - \hat Y(0)\]

This is zero for observations that were never treated, and nonzero for
the treated-post treatment observations.\footnote{The case of
  pre-treatment treated observations may be assumed to be zero if the
  \texttt{never} option is not used. When \texttt{never} is used,
  pre-treatment ATTs can be used for testing the parallel trends
  assumption.}

From here, any aggregated average treatment effects can be calculated as
follows:

\[AGGTE_r =  \frac{ \sum_i^N\widehat{ATT}_i \times w_{i,t} \times R_{i,t}}{ \sum_i^N  w_{i,t} \times R_{i,t}}  
\]

where \(R_{i,t}\) takes the value of one whenever observation \(i\)
fullfills the required conditions, and \(w_{i,t}\) is the weight of the
observation \(i\) at time \(t\) used in for the estimation model.
\footnote{While this is the default option, \texttt{estat} command also
  allow you to provide other weights for aggregation}. \(AGGTE\) is the
aggregated average treatment effect on the treated given the conditions
\(R\).

In general, there are four types of aggregations that are implemented in
the \texttt{jwdid\_estat/estat} command:

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
  \texttt{estat\ simple}: This option calculates the average treatment
  effect on the treated for all observations that were treated at some
  point in time. The condition \(R\) is defined as:
\end{enumerate}

\[\begin{aligned}
R_{i,t} &= 1 \text{ if } t \geq g \text{ for observation } i \in g \\
R_{i,t} &= 0 \text{ otherwise}
\end{aligned}
\]

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{1}
\tightlist
\item
  \texttt{estat\ group}: This option calculates the average treatment
  effect for observations that were treated at time \(g\). The condition
  \(R\) is defined as:
\end{enumerate}

\[\begin{aligned}
R_{i,t} &= 1 \text{ if } t \geq g_c \text{ for observation } i \\
R_{i,t} &= 0 \text{ otherwise}
\end{aligned}
\]

where \(g_c\) is a particular group/cohort of interest.
\texttt{estat\ group} estimates this for all groups \(g\) in \(G\).

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{2}
\tightlist
\item
  \texttt{estat\ time}: This option calculates the average treatment
  effect at time \(t\) for all observations that were effectively
  treated at that point. The condition \(R\) is defined as:
\end{enumerate}

\[\begin{aligned}
R_{i,t} &= 1 \text{ if } t_c \geq g \text{ for observation } i \\
R_{i,t} &= 0 \text{ otherwise}
\end{aligned}
\]

where \(t_c\) is a particular time of interest. \texttt{estat\ time}
estimates this for all times \(t\) in \(T\) that has at least one unit
that was treated.

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{3}
\tightlist
\item
  \texttt{estat\ event}: This option calculates dynamic treatment
  effects, also known as event studies, using the period before
  treatment as the reference. When the condition `never' is used, this
  approach can be used to estimate pre-treatment ATT's, which could be
  used for testing PTA. The condition \(R\) is defined as:
\end{enumerate}

\[\begin{aligned}
R_{i,t} &= 1 \text{ if } t-g = e_c \text{ \& } e \neq -1 \text{ for observation } i \\
R_{i,t} &= 0 \text{ otherwise}
\end{aligned}
\]

where \(e_c\) is a particular event of interest. In contrast with the
previous aggregations, if option \texttt{never} was used for estimation,
one could also add the option \texttt{pretrend} to run a simple PTA test
with the following null hypothesis:

\[H_0: AGGTE_e = 0 \text{ for all } e < -1 \text{ vs }H_1: AGGTE_e \neq 0 \text{ for some } e < -1\]

Failure to reject this hypothesis is evidence in support of parallel
trends assumption. Otherwise, one can use \texttt{test} command to test
for the significance of specific pre-treatment ATT's.\footnote{It should
  be noticed that this test is different from the test proposed by
  Callaway and Sant'Anna (2021), which is based on testing \emph{all}
  group/time specific ATT's, instead of the event aggregated ones.}

\subsection{Post estimation: Other
options}\label{post-estimation-other-options}

The \texttt{jwdid\_estat}/\texttt{estat} command allows for further
options that may be of interest for the user. In this section we provide
a brief description of those options:

\subsubsection{Weights}\label{weights}

The default option for the estimation of the aggregated ATTs is to use
the weights \(w_{i,t}\) that were used in the estimation of the model.
However, if the user wants to use different weights, it is possible to
do using the following syntax:

\texttt{estat\ {[}aggregation{]}\ {[}pw\ =\ weight{]}}

\subsubsection{Standard Errors}\label{standard-errors}

Jeffrey M. Wooldridge (2021) suggests than when one estimates standard
errors for the aggregated ATTs, one should use
\texttt{vce(unconditional)} option in \texttt{Stata}, to allow for
uncertainty in the explanatory variables.
\texttt{jwdid\_estat}/\texttt{estat} does not use this approach by
default, because it requires that the underlying command is able to
produce Scores for the estimated model. For example, if the model was
estimated using \texttt{method(regress)}, the Scores will be available,
and unconditional Standard errors for the aggregated ATTs can be
estimated as follows:

\texttt{estat\ {[}aggregation{]},\ {[}vce(unconditional){]}}

This is not possible if one uses the default methodology
\texttt{reghdfe}.

\subsubsection{Other Aggregation
restrictions}\label{other-aggregation-restrictions}

As described in Section~\ref{sec-agg}, the default aggregation considers
all observations treated observations, impossing restrictions only in
terms of time, group or event dimensions. However, one may be interested
in imposing further restrictions that could leverage on the use of
covariates in the model specification. For example, say that one
estimates a DID model with covariates using the following syntax:

\texttt{jwdid\ y\ i.dx,\ ivar(i)\ tvar(t)\ gvar(g)\ never}

As usual, one could request the estimation of the aggregated ATTs for
the whole sample as follows:

\texttt{estat\ {[}aggregation{]}}

However, one would also be able to make the same estimation imposing the
added restriction that the covariate \texttt{dx} is zero or one, using
the option \texttt{orestriction()}:

\texttt{estat\ {[}aggregation{]},\ orestriction(dx==0)}

\texttt{estat\ {[}aggregation{]},\ orestriction(dx==1)}

The expression inside the parenthesis should be a valid Stata expression
that is used when calculating the aggregated ATTs.

\subsubsection{Storing, and saving
results}\label{storing-and-saving-results}

After aggregate effects have been estimated, the user may want to store
the results for further analysis or reporting. Because \texttt{estat}
uses \texttt{margins} in the background, the default option is to store
the results in memory as \texttt{r()} elements. Alternatively,
\texttt{jwdid\_estat}/\texttt{estat} allows the user to store the output
of the command using three different options:

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
  \texttt{estat\ {[}aggregation{]},\ post}: As with margins, option
  \texttt{post} will ``post'' the results of the command to be the
  current estimations in memory \texttt{e()}, which can be saved as
  usual for further analysis.
\item
  \texttt{estat\ {[}aggregation{]},\ estore(name)}: This option stores
  the results from the aggregation in memory as \texttt{name}. This is
  similar to using \texttt{estimation\ store\ name} after a regression
  command. The previously estimated results from \texttt{jwdid} are not
  overwritten.
\item
  \texttt{estat\ {[}aggregation{]},\ esave(filename)}: This option saves
  the results from the aggregation in a file \texttt{filename}, as a
  \texttt{ster} file, which can be used at a later point.
\end{enumerate}

\subsubsection{Plotting}\label{plotting}

After \textbf{time}, \textbf{group} or \textbf{event} aggregations are
estimated, it is possible to request plotting those results using
\texttt{estat\ plot}. The basic syntax is to type it after the
aggregation command, with only minimal command specific options:

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\item
  \texttt{estat\ plot,\ style(style)}: The option \texttt{style} allows
  the user to select the style of the plot. The default is using a
  \texttt{rspike} style, but \texttt{rarea}, \texttt{rcap} and
  \texttt{rbar} are also available. See \texttt{help\ twoway} for more
  information on the styles.
\item
  \texttt{estat\ plot,\ \ pstyle1(str)\ color1(str)\ pstyle2(str)\ color2(str)\ lwidth1(str)\ lwidth2(str)\ barwidth1(str)\ barwidth2(str)}:
  The options \texttt{pstyle\#}, \texttt{color\#}, \texttt{lwidth\#} and
  \texttt{barwidth\#} can be used to alter the color and style of the
  lines in the plot for the pre and post treatment periods. Only
  \texttt{event} aggregation allows for \texttt{\#2} options.
\item
  \texttt{estat\ plot,\ twoway\_options}: Most other \texttt{twoway}
  graph option can be used after the \texttt{estat\ plot} command.
\end{enumerate}

\section{Appendix}\label{appendix}

\phantomsection\label{refs}
\begin{CSLReferences}{1}{0}
\bibitem[\citeproctext]{ref-borusyak2023}
Borusyak, Kirill, Xavier Jaravel, and Jann Spiess. 2024. {``{Revisiting
Event-Study Designs: Robust and Efficient Estimation}.''} \emph{The
Review of Economic Studies}, February, rdae007.
\url{https://doi.org/10.1093/restud/rdae007}.

\bibitem[\citeproctext]{ref-callaway2021}
Callaway, Brantly, and Pedro H. C. Sant'Anna. 2021.
{``Difference-in-{Differences} with Multiple Time Periods.''}
\emph{Journal of Econometrics}, Themed {Issue}: {Treatment} {Effect} 1,
225 (2): 200--230. \url{https://doi.org/10.1016/j.jeconom.2020.12.001}.

\bibitem[\citeproctext]{ref-correira2016}
Correia, Sergio. 2016. {``A {Feasible} {Estimator} for {Linear} {Models}
with {Multi}-{Way} {Fixed} {Effects}.''}

\bibitem[\citeproctext]{ref-correia2020}
Correia, Sergio, Paulo Guimarães, and Tom Zylkin. 2020. {``Fast
{Poisson} Estimation with High-Dimensional Fixed Effects.''} \emph{The
Stata Journal} 20 (1): 95--115.
\url{https://doi.org/10.1177/1536867X20909691}.

\bibitem[\citeproctext]{ref-dechaisemartin2020}
De Chaisemartin, Clément, and Xavier D'Haultfœuille. 2020. {``Two-{Way}
{Fixed} {Effects} {Estimators} with {Heterogeneous} {Treatment}
{Effects}.''} \emph{American Economic Review} 110 (9): 2964--96.
\url{https://doi.org/10.1257/aer.20181169}.

\bibitem[\citeproctext]{ref-rothsantana2023}
Roth, Jonathan, and Pedro H. C. Sant'Anna. 2023. {``When {Is} {Parallel}
{Trends} {Sensitive} to {Functional} {Form}?''} \emph{Econometrica} 91
(2): 737--47. \url{https://doi.org/10.3982/ECTA19402}.

\bibitem[\citeproctext]{ref-sunabraham2021}
Sun, Liyang, and Sarah Abraham. 2021. {``Estimating Dynamic Treatment
Effects in Event Studies with Heterogeneous Treatment Effects.''}
\emph{Journal of Econometrics}, Themed {Issue}: {Treatment} {Effect} 1,
225 (2): 175--99. \url{https://doi.org/10.1016/j.jeconom.2020.09.006}.

\bibitem[\citeproctext]{ref-wooldridge2023}
Wooldridge, Jeffrey M. 2023. {``Simple Approaches to Nonlinear
Difference-in-Differences with Panel Data.''} \emph{The Econometrics
Journal} 26 (3): C31--66. \url{https://doi.org/10.1093/ectj/utad016}.

\bibitem[\citeproctext]{ref-wooldridge2021}
Wooldridge, Jeffrey M. 2021. {``Two-{Way} {Fixed} {Effects}, the
{Two}-{Way} {Mundlak} {Regression}, and {Difference}-in-{Differences}
{Estimators}.''} \{SSRN\} \{Scholarly\} \{Paper\}. Rochester, NY.
\url{https://doi.org/10.2139/ssrn.3906345}.

\end{CSLReferences}



\end{document}
